package com.k.kc.util;

import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * @author net
 */
public class RiLiStd {
    private static final String[] MONTH_ARR = new String[]{
            "Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
    private static final String[] WEEK_ARR = new String[]{
            "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    };

    private static void printStd() {
        try (Scanner sc = new Scanner(System.in)) {
            System.out.println("please input the year:");
            int year = sc.nextInt();
            System.out.println("please input the month:");
            int month = sc.nextInt();
            printStdRiLi(year, month);
        }
    }

    private static void printStdRiLi(int year, int month) {
        System.out.printf("\n         %s, %4d\n", MONTH_ARR[month - 1], year);
        System.out.println("-----------------------------");
        System.out.println("  " + StringUtils.join(WEEK_ARR, " "));

        Calendar c = Calendar.getInstance();
        c.set(year, month - 1, 1);
        //int totalDay = c.getActualMaximum(Calendar.DATE);
        int totalDay = DateUtils.getDaysOfMonth(year,month);
        for (int i = 1; i < c.get(Calendar.DAY_OF_WEEK); i++) {
            System.out.print("    ");
        }
        for (int i = 1; i <= totalDay; i++) {
            c.set(year, month - 1, i);
            System.out.printf("%4d", i);
            if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
                System.out.println("");
            }

        }
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        int year = 2022;
        for(int i=1;i<=12;i++){
            printStdRiLi(year,i);
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
